<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>

<title>appscript | 1. Introduction</title>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<style type="text/css" media="all"><!--@import url(full.css);--></style>

</head>
<body>

<h1>1. Introduction</h1>

<!-- top navigation -->
<div class="navbar">
	<a href="index.html">Previous</a> | <a href="index.html">Up</a> | <a href="02_aboutappscripting.html">Next</a>
	
</div>

<!-- content -->
<div id="content">


<h2>What is appscript?</h2>

<p>Objc-appscript is a high-level Apple event bridge that allows you to control scriptable Mac OS X applications from Objective-C programs.</p>

<p>For example, to get the value of the first paragraph of the topmost document in TextEdit:</p>

<pre><code>TEApplication *textedit = [[TEApplication alloc]
                            initWithName: @"TextEdit.app"];

NSString *result = [[[[[[textedit documents] at: 1] 
                                 paragraphs] at: 1] get] send];</code></pre>

<p>This is equivalent to the AppleScript statement:</p>

<pre><code>tell application "TextEdit"
    get paragraph 1 of document 1
end tell</code></pre>

<p>Appscript builds upon the Apple Event Manager and Foundation APIs to provide:</p>

<ol>
<li>a high-level <em>RPC mechanism</em> for sending commands to applications via Apple events</li>
<li>a mechanism for converting data between common Foundation and Apple event types</li>
<li>a simple <em>programmatic query language</em> for identifying one or more objects in an application's object model</li>
<li>a glue code generator for representing these object model "references" in human-readable form based on application-defined terminology</li>
<li>a clean, <em>object oriented-like</em> syntax for ease of use.</li>
</ol>

<p>Appscript requires Mac OS X 10.3 or later.</p>



<h2>"Hello World!"</h2>

<p>The following program uses appscript to create a new "Hello World!" document in TextEdit:</p>

<pre><code>#import &lt;Foundation/Foundation.h&gt;
#import "TEGlue.h"

int main(int argc, char *argv[]) {
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    	
    TEApplication *textedit;
    TEMakeCommand *makeCmd;
    
    textedit = [[TEApplication alloc]
                 initWithName: @"TextEdit.app"];
    
    makeCmd = [[[textedit make] new_: [TEConstant document]]
                      withProperties: [NSDictionary dictionaryWithObjectsAndKeys:
                                       @"Hello World!\n", [TEConstant text], nil]];
    [makeCmd send];
    
    [textedit release];
    [pool release];
    return 0;
}</code></pre>


<!-- TO DO
<h2>Notes</h2>

<p>Objc-appscript is a port of the robust, mature Python appscript (py-appscript) bridge.</p>
-->

</div>

<!-- bottom navigation -->
<div class="navbar">
	<a href="index.html">Previous</a> | <a href="index.html">Up</a> | <a href="02_aboutappscripting.html">Next</a>
	
</div>

<!--footer-->
<p class="footer">&copy; 2007 HAS</p>
</body>
</html>